package cn.jorian.framework.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
public class RedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void setKey(String key, String value) {
        ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key, value);
    }

    public String getKey(String key) {
        String value = "";
        Boolean isHas = redisTemplate.hasKey(key);
        if (isHas) {
           value = (String) redisTemplate.opsForValue().get(key);
        }

        return value;
    }

}
